<?php
namespace App\Models\Admin;

class YzmModel extends BaseModel
{
    /**
     * 验证码
     */

    protected $table = 'users_yzm';
    protected $fillable = [
        'id','phone','code','status','created_at',
    ];

    /**
     * 发送状态：1发送失败，2发送成功
     */

    public function getAdminIndex()
    {
        $models = YzmModel::paginate(10);
        $models->limit = 10;
        return $models;
    }



    /**
     * 判断验证码是否有效
    */
    public static function isExists($phone,$yzm){
        $ex=YzmModel::whereRaw('phone = ? AND code =? AND created_at > ?',[
            $phone,$yzm,time()-(60*5)
        ])->exists();
        if(!$ex){
            return $ex;
        }
        YzmModel::whereRaw('phone = ? AND code =? AND created_at > ?',[
            $phone,$yzm,time()-(60*5)
        ])->delete();
        return true;
    }
}